import { WriteFileOptions } from 'fs'

import { writeFileAsync } from '../utils'

export function writeStartScript(commands: string[], path: string, options: WriteFileOptions = {}) {
  const shebang = '#!/usr/bin/env bash'

  const content = [
    shebang,
    '\n',
    'source /etc/profile',
    'export NVM_NODEJS_ORG_MIRROR=https://bnpm.bytedance.net/mirrors/node',
    'nvm install 14',
    'nvm use 14',
    ...commands,
  ].join('\n')

  return writeFileAsync(path, content, options)
}
